package com.soft.hwx.scdapp.main;

import android.util.Log;

import com.soft.hwx.scdapp.msg.RawMsg;

/*
  侦察主机
 */
public class ScoutHost {
    private  HostRecvThread  recvObj;
    private  Thread recvThread;
    private  HostSendThread  sendObj;
    private  Thread sendThread;
    private  ScoutHostInterface mScoutHostInterface;
    private String dstIP;
    private int dstPort;


    public ScoutHost(ScoutHostInterface scoutHostInterface,String dstIP,int dstPort){
        mScoutHostInterface = scoutHostInterface;
        this.dstIP = dstIP;
        this.dstPort = dstPort;
    }


    public int Init()
    {
        recvObj = new HostRecvThread(mScoutHostInterface);
        recvThread = new Thread(recvObj);

        sendObj = new HostSendThread(this.dstIP,this.dstPort);
        sendThread = new Thread(sendObj);

        try {
            Log.d("HostRecvThread", "启动接收线程");
            recvThread.start();
        }catch (Exception e){
            Log.d("HostRecvThread", "创建侦查主机接收线程失败:"+e.getMessage());
            return -1;
        }

        try {
            Log.d("HostSendThread", "启动发送线程");
            sendThread.start();
        }catch (Exception e){
            Log.d("HostSendThread", "创建侦查主机发送线程失败:"+e.getMessage());
            return -1;
        }

        return 0;
    }

    public int ShUdpClientSendCmd(RawMsg msg){
        sendObj.udpClientSendCmd(msg);
        return 0;
    }

}
